﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;


namespace HandMade_Q4T_
{
    public class C_SanPham
    {
        C_XLDL db = new C_XLDL();

        string masp, hinhsp, tensp, tenloai,tencl,ngaycapnhat,tenncc, mota, macl, maloai, mancc;
        int soluong, dongia, solanxem;

        #region Properties
        public string Masp
        {
            get { return masp; }
            set { masp = value; }
        }

        public string Hinhsp
        {
            get { return hinhsp; }
            set { hinhsp = value; }
        }

        public string Tensp
        {
            get { return tensp; }
            set { tensp = value; }
        }

        public string Mota
        {
            get { return mota; }
            set { mota = value; }
        }

        public string Macl
        {
            get { return macl; }
            set { macl = value; }
        }

        public string Tencl
        {
            get { return tencl; }
            set { tencl = value; }
        }

        public string Maloai
        {
            get { return maloai; }
            set { maloai = value; }
        }

        public string Tenloai
        {
            get { return tenloai; }
            set { tenloai = value; }
        }

        public string Mancc
        {
            get { return mancc; }
            set { mancc = value; }
        }

        public string Tenncc
        {
            get { return tenncc; }
            set { tenncc = value; }
        }  

        public int Soluong
        {
            get { return soluong; }
            set { soluong = value; }
        }

        public int Dongia
        {
            get { return dongia; }
            set { dongia = value; }
        }

        public int Solanxem
        {
            get { return solanxem; }
            set { solanxem = value; }
        }

        public string Ngaycapnhat
        {
            get { return ngaycapnhat; }
            set { ngaycapnhat = value; }
        }
        #endregion

        #region Load Data -> Controls
        /// <summary>
        /// Load data -> Dropdownlist
        /// </summary>
        /// <param name="ddl">ID Dropdownlist</param>
        /// <param name="sqlQuery">Chuỗi truy vấn</param>
        /// <param name="display">Trường cần hiển thị (VD: tenloai)</param>
        /// <param name="value">Trường cần lưu (VD: maloai)</param>
        public void Load_DropDownlist(DropDownList ddl, string sqlQuery, string display, string value)
        {
            ddl.DataSource = db.BangDuLieu(sqlQuery);
            ddl.DataTextField = display;
            ddl.DataValueField = value;
            ddl.DataBind();
        }

        /// <summary>
        /// Load data -> Repeater
        /// </summary>
        /// <param name="rpt">ID repeater</param>
        /// <param name="sqlQuery">Chuỗi truy vấn</param>
        public void Load_Repeater(Repeater rpt, string sqlQuery)
        {
            rpt.DataSource = db.BangDuLieu(sqlQuery);
            rpt.DataBind();
        }

        /// <summary>
        /// Load categori with datalist
        /// </summary>
        /// <param name="l">id datalist</param>
        /// <param name="sql">Chuỗi truy vấn</param>
        public void Load_Datalist(DataList l, string sql)
        {
            l.DataSource = db.BangDuLieu(sql);
            l.DataBind();
        }

        public DataTable Get_Data(string sql)
        {
            DataTable dt = new DataTable();
            dt = db.BangDuLieu(sql);
            return dt;
        }

        public bool Update_Data(string sql)
        {
            try
            {
                db.ThucHienLenh(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion



        internal void Load_Datalist(System.Web.UI.HtmlControls.HtmlGenericControl lis_loaisp, string p)
        {
            throw new NotImplementedException();
        }
    }
}